package com.admin.business.background.venusSysUserLog;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 用户登录日志表
 * @create: 2023-10-23 14:31:53
 **/
@Service("venusSysUserLogService")
@Slf4j
public class VenusSysUserLogService{

    @Resource
    VenusSysUserLogDao venusSysUserLogDao;

    /**
     * 添加用户登录日志表,获取log_id数据
     *
     * @param cdoRequest - log_id:
     *                   - sys_user_id:系统用户id
     *                   - log_type:操作类型
     *                   - log_operation:操作内容
     *                   - log_create_time:操作时间
     *                   - log_ip:操作IP
     *                   - log_result:操作结果
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return addVenusSysUserLog(CDO cdoRequest) {
        venusSysUserLogDao.addVenusSysUserLog(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("log_id")) {
            cdoResult.set("log_id", cdoRequest.get("log_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据log_id，更新用户登录日志表数据
     *
     * @param cdoRequest - log_id:
     *                   - sys_user_id:系统用户id
     *                   - log_type:操作类型
     *                   - log_operation:操作内容
     *                   - log_create_time:操作时间
     *                   - log_ip:操作IP
     *                   - log_result:操作结果
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return updateVenusSysUserLogById(CDO cdoRequest) {
        venusSysUserLogDao.updateVenusSysUserLogById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据log_id，删除用户登录日志表数据
     *
     * @param cdoRequest - log_id:
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusSysUserLogById(CDO cdoRequest){
        int count = venusSysUserLogDao.deleteVenusSysUserLogById(cdoRequest.getLong("log_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除用户登录日志表数据
     *
     * @param cdoRequest - sys_user_id:系统用户id
     *                   - log_type:操作类型
     *                   - log_result:操作结果
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusSysUserLog(CDO cdoRequest) {
        int count = venusSysUserLogDao.deleteVenusSysUserLog(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取用户登录日志表数据
     *
     * @param cdoRequest - log_id:
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusSysUserLogById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysUserLogDao.getVenusSysUserLogById(cdoRequest.getLong("log_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取用户登录日志表数据列表
     *
     * @param cdoRequest - sys_user_id:系统用户id
     *                   - log_type:操作类型
     *                   - log_result:操作结果
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusSysUserLogListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserLogDao.getVenusSysUserLogListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserLogDao.getVenusSysUserLogCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取用户登录日志表数据列表
     *
     * @param cdoRequest - log_id:
     *                   - sys_user_id:系统用户id
     *                   - log_type:操作类型
     *                   - log_result:操作结果
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusSysUserLogListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserLogDao.getVenusSysUserLogListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserLogDao.getVenusSysUserLogCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
